//
//  CarVc.swift
//  XXIOT
//
//  Created by xx on 2024/8/23.
//

import UIKit
import FastSwiftSDK

class CarPayViewController: FastViewController {

    private lazy var carView : CarView = {
        let view = CarView()
        self.view.addSubview(view)
        return  view
    } ()
    
    let bt = XXBTManager.shared
    
    override func viewDidLoad() {
        super.viewDidLoad()
        self.view.backgroundColor = .white
        
        self.carView.setState(type: "MQ", state: XXMQTT.shared.connectState)
        XXMQTT.shared.connectCallBack = {[weak self] state in
            if state == "didConnectAck"{
                self?.carView.setState(type: "MQ", state: 1)
            }
            
            if state == "disconnect"{
                self?.carView.setState(type: "MQ", state: 0)
            }
        }
        
        XXBTManager.shared.stateBlock = {[weak self] state in
            self?.carView.setState(type: "BT", state: state)
        }
        
        
    }
        
    override func viewWillAppear(_ animated: Bool) {
        super.viewWillAppear(animated)
        //这里是强制竖屏  希望什么方向修改这个枚举即可
        UIDevice.current.setValue(NSNumber(value: UIDeviceOrientation.landscapeRight.rawValue), forKey: "orientation")
        UIApplication.shared.setStatusBarOrientation(.portrait, animated: false)
        
    }
    override func viewWillLayoutSubviews() {
        super.viewWillLayoutSubviews()
        carView.snp.makeConstraints { make in
            make.edges.equalToSuperview()
        }
    }
    
    //禁止这个控制器旋转 在viewdidapear前要return ture   didapear后 return  false
    override var shouldAutorotate: Bool {
        return false
    }
}
